// 登录接口
import {request} from '../utils/request'

const questionApi = {
  updateQuestion: '/question/update',
  getKnowledgePoints: '/subject/getKnowledgePoints',
  findKnowledgePointByID: '/subject/findKnowledgePointByID',
  addQuestion: '/question/add',
  queryById: '/question/queryById',
  deleteQuestion: '/question/delete'
}

// 更新题库中题目
export function updateQuestion (questionInfo) {
  return request({
    url: questionApi.updateQuestion,
    method: 'post',
    data: {
      answer: questionInfo.answer,
      createTime: questionInfo.createTime,
      id: questionInfo.id,
      knowledgePointId: questionInfo.knowledgePointId,
      questionStem: questionInfo.questionStem,
      questionType: questionInfo.questionType,
      subjectId: questionInfo.subjectId,
      teacherId: questionInfo.teacherId,
      updateTime: questionInfo.updateTime,
      examQuestion: questionInfo.examQuestion
    }
  })
}

// 获取全部知识点
export function getKnowledgePoints (subjectId) {
  return request({
    url: questionApi.getKnowledgePoints,
    method: 'get',
    params: {
      subjectId: subjectId
    }
  })
}

// 根据id获取知识点
export function findKnowledgePointByID (id) {
  return request({
    url: questionApi.findKnowledgePointByID,
    method: 'get',
    params: {
      id: id
    }
  })
}

// 增加题目
export function addQuestion (questionInfo) {
  return request({
    url: questionApi.addQuestion,
    method: 'post',
    data: {
      answer: questionInfo.answer,
      createTime: '',
      updateTime: '',
      knowledgePointId: questionInfo.knowledgePointId,
      paperList: [],
      questionStem: questionInfo.questionStem,
      questionType: questionInfo.questionType,
      subjectId: questionInfo.subjectId,
      teacherId: questionInfo.teacherId,
      examQuestion: questionInfo.examQuestion
    }
  })
}

// 增加题目
export function queryById (id) {
  return request({
    url: questionApi.queryById,
    method: 'get',
    params: {
      questionId: id
    }
  })
}

// 删除题目
export function deleteQuestion (questionId) {
  return request({
    url: questionApi.deleteQuestion,
    method: 'post',
    data: questionId
  })
}
